﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Routing;
using RMS.Models.Repository;

namespace RMS.Controls
{
    /* Form Control -- generates retreat browsing side bar links; only included on certain pages */

    public partial class CategoryList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e) {

        }

        protected IEnumerable<string> GetCategories()
        {
            return new Repository().Retreats.Select(p => p.Ret_Main_Category).Distinct().OrderBy(x => x);
        }

        protected string CreateHomeLinkHtml()
        {
            string path = RouteTable.Routes.GetVirtualPath(null, null).VirtualPath;
            return string.Format("<a href='{0}'>Retreat Catalog</a>", path);
        }

        protected string CreateLinkHtml(string category) {
            string selectedCategory = (string)Page.RouteData.Values["category"]
                ?? Request.QueryString["category"];
                   
            
            string path = RouteTable.Routes.GetVirtualPath(null, null,
                new RouteValueDictionary() { { "category", category },
                {"page", "1"} }).VirtualPath;

            return string.Format("<a href='{0}' {1}>{2}</a>",
                path, category == selectedCategory ? "class='selected'" : "", category);
        }

    }
}